package com.weixing.mall.provider.controller.cms;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.base.enums.IsEnableEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.cms.LocalStoreDto;
import com.weixing.mall.provider.model.query.LocalStoreQuery;
import com.weixing.mall.provider.service.ILocalStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/7/26 15:11
 * @Version 1.0
 */
@RestController
@RequestMapping("localStore")
@Api(value = "实体店铺管理Api",tags = "实体店铺管理")
public class LocalStoreController extends BaseController {
    @Autowired
    private ILocalStoreService localStoreService;

    @ApiOperation(value = "加载实体店铺")
    @GetMapping("")
    public Result list(LocalStoreQuery localStoreQuery){
        return ResultUtil.success(localStoreService.selectOfPage(initMpPage(),localStoreQuery));
    }

    @ApiOperation(value = "查看店铺详情")
    @PostMapping("selectDetails/{id}")
    public Result selectDetails(@PathVariable long id){
        return ResultUtil.success(localStoreService.selectLocalStoreEditVoById(id));
    }

    @ApiOperation(value = "保存实体店铺")
    @PostMapping("save")
    public Result save(@Validated LocalStoreDto localStoreDto){
        localStoreService.save(localStoreDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除实体店铺")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "店铺id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id){
        return localStoreService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "修改状态")
    @PostMapping("chgEnable")
    public Result changeEnable(Long id, IsEnableEnum isEnable){

        localStoreService.changeEnable(id,isEnable);
        return ResultUtil.success();
    }
}
